package com.hxexp.weixin.test;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import com.hxexp.weixin.test.runner.JUnit4WithSpringLogClassRunner;
import com.qq.weixin.constant.AppDevConstant;
import com.qq.weixin.mp.api.base.BaseAPI;
import com.qq.weixin.mp.api.base.model.AccessTokenBean;
import com.qq.weixin.mp.api.base.model.CallbackIPBean;

/**
 * BaseAPI测试
 * @author li.jiang
 *
 */
@RunWith(JUnit4WithSpringLogClassRunner.class)
@ContextConfiguration(locations={"classpath:conf/spring/spring-biz.xml", "classpath:conf/spring/spring-ehcache.xml"})
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class BaseAPITester {
    @Autowired
    private BaseAPI baseAPI;
    private static String accessToken;

    /**
     * 测试getAccessToken()方法
     */
    @Test
    public void testCase01_getAccessToken() {
        try {
            AccessTokenBean accessTokenBean = baseAPI.getAccessToken(AppDevConstant.HxExp.APPID, AppDevConstant.HxExp.APPSECRET);
            accessToken = accessTokenBean.getAccessToken();
            System.out.println("当前获取到的Access Token: " + accessToken);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 测试getCallbackIP()方法
     */
    @Test
    public void testCase02_getCallbackIP() {
        try {
            CallbackIPBean callbackIPBean = baseAPI.getCallbackIP(accessToken);
            System.out.println("获取到的微信服务器地址：");
            System.out.println(callbackIPBean);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
